package com.yxuan.springboot.controller;


import io.swagger.annotations.Api;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@Api(tags = "发送MQ消息测试")
@RestController
@RequestMapping("/SendMQMessageTestController")
public class SendMQMessageTestController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @ResponseBody
    @RequestMapping("/MQtest")
    public String MQtest(Integer j){

        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
        Date date = new Date(System.currentTimeMillis());
        System.out.println(formatter.format(date));

            String orderId = String.valueOf(j);
            // 交换机名称
            String exchange = "wxzhifu.exchange";
            // 发送消息
            rabbitTemplate.convertAndSend(exchange,"wxt", orderId);
            System.out.println("发送"+j+"消息成功");


        SimpleDateFormat formatter2= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
        Date date2 = new Date(System.currentTimeMillis());
        System.out.println(formatter2.format(date2));



        return "发送消息成功";


    }

}
